/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.uac.pages.user;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import com.eelpo.cmmp.core.wicket.panel.container.SearchPanel;
import com.eelpo.cmmp.uac.dao.vo.User;
import com.eelpo.cmmp.uac.dao.vo.enumed.AuthMode;
import com.eelpo.cmmp.uac.dao.vo.enumed.Status;
import com.eelpo.cmmp.uac.dao.vo.enumed.YesOrNo;

/**
 * <pre>
 * 用户管理查询参数面板
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class UserSearchPanel extends SearchPanel {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 4897791468268434575L;

	public UserSearchPanel(String id, User user) {
		super(id);

		add(renderFeedbackPanel("feedback"));

		renderUserNameTextField(user);
		renderUserMobileTextField(user);
		renderUserAccountTextField(user);
		renderUserDescriptionTextField(user);
		renderUserStatusDropDownChoice(user);
		renderUserWebLoginDropDownChoice(user);
		renderUserWebAuthDropDownChoice(user);
		renderUserInterfaceLoginDropDownChoice(user);
		renderUserInterfaceAuthDropDownChoice(user);

		renderAddButton();
	}

	public void renderUserNameTextField(User user) {
		add(new TextField<String>("txtName", new PropertyModel<String>(user, "name")));
	}

	public void renderUserMobileTextField(User user) {
		add(new TextField<String>("txtMoblie", new PropertyModel<String>(user, "mobile")));
	}

	public void renderUserAccountTextField(User user) {
		add(new TextField<String>("txtAccount", new PropertyModel<String>(user, "account")));
	}

	public void renderUserDescriptionTextField(User user) {
		add(new TextField<String>("txtDescription", new PropertyModel<String>(user, "description")));
	}

	public void renderUserStatusDropDownChoice(final User user) {
		List<Status> dataList = Arrays.asList(Status.ENABLED, Status.DISABLED, Status.ALL);
		IModel<Status> model = new PropertyModel<Status>(user, "status");
		IChoiceRenderer<Status> choiceRenderer = new ChoiceRenderer<Status>("label", "value");
		DropDownChoice<Status> userStatus = new DropDownChoice<Status>("selStatus", model, dataList, choiceRenderer);
		add(userStatus);
	}

	public void renderUserWebLoginDropDownChoice(final User user) {
		List<YesOrNo> dataList = Arrays.asList(YesOrNo.values());
		IModel<YesOrNo> model = new PropertyModel<YesOrNo>(user, "allowWebLogin");
		IChoiceRenderer<YesOrNo> choiceRenderer = new ChoiceRenderer<YesOrNo>("label", "value");
		DropDownChoice<YesOrNo> userWebLogin = new DropDownChoice<YesOrNo>("selWeblogin", model, dataList, choiceRenderer);
		add(userWebLogin);
	}

	public void renderUserWebAuthDropDownChoice(final User user) {
		List<AuthMode> dataList = Arrays.asList(AuthMode.values());
		IModel<AuthMode> model = new PropertyModel<AuthMode>(user, "webAuthMode");
		IChoiceRenderer<AuthMode> choiceRenderer = new ChoiceRenderer<AuthMode>("label", "value");
		DropDownChoice<AuthMode> userWebAuth = new DropDownChoice<AuthMode>("selWebauth", model, dataList, choiceRenderer);
		add(userWebAuth);
	}

	public void renderUserInterfaceLoginDropDownChoice(final User user) {
		List<YesOrNo> dataList = Arrays.asList(YesOrNo.values());
		IModel<YesOrNo> model = new PropertyModel<YesOrNo>(user, "allowInterface");
		IChoiceRenderer<YesOrNo> choiceRenderer = new ChoiceRenderer<YesOrNo>("label", "value");
		DropDownChoice<YesOrNo> userItfLogin = new DropDownChoice<YesOrNo>("selInterfacelogin", model, dataList, choiceRenderer);
		add(userItfLogin);
	}

	public void renderUserInterfaceAuthDropDownChoice(final User user) {
		List<AuthMode> dataList = Arrays.asList(AuthMode.values());
		IModel<AuthMode> model = new PropertyModel<AuthMode>(user, "interfaceAuthMode");
		IChoiceRenderer<AuthMode> choiceRenderer = new ChoiceRenderer<AuthMode>("label", "value");
		DropDownChoice<AuthMode> userItfAuth = new DropDownChoice<AuthMode>("selInterfaceauth", model, dataList, choiceRenderer);
		add(userItfAuth);
	}

	private void renderAddButton() {
		Link<Void> lnkAdd = new Link<Void>("btnAdd") {
			private static final long serialVersionUID = -940868358118439402L;

			public void onClick() {
				setResponsePage(new AddOrEditUser());
			}
		};
		add(lnkAdd);
	}

}
